﻿using Help;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLLA
{
    public partial class Order_OrgWalt_T : BaseBLL<Model.Order_OrgWalt_T>, IBLL.IOrder_OrgWalt_TBLL
    {
        ObjectSerialize os = new ObjectSerialize();
        DataResult result = new DataResult();
        IBLL.IBLLSession bl = DI.SpringHelper.GetObject<IBLL.IBLLSession>("BLLSession");
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Data"></param>
        /// <param name="tag"></param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string SetOrgWalt(string Data, int tag, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            #region 执行操作
            try
            {
                Model.Order_OrgWalt_T info = ParseClass<Model.Order_OrgWalt_T>.StrDeserialize(Data, RETID);
                string T = "";
                int ret = -1;
                // 根据操作标签Tag判断是什么操作
                switch (tag)
                {
                    case 1:
                        T = "新增";
                        List<Model.Order_OrgWalt_T> OrgWaltList = new List<Model.Order_OrgWalt_T>();
                        OrgWaltList = base.GetListBy(u => u.FormMerID == info.FormMerID);
                        if (OrgWaltList != null & OrgWaltList.Count > 0)
                        {
                            Model.Order_OrgWalt_T tmp1 = OrgWaltList[0];
                            Help.FuZhi<Model.Order_OrgWalt_T>.FZ(ref tmp1, info);
                            tmp1.OrgWaltState = 1;
                            ret = base.Modify(tmp1);
                        }
                        else
                        {
                            info.OrgWaltID = int.Parse( GetSysKey.GetKey("WaltKey"));
                            ret = base.Add(info);
                        }
                        break;
                    case 2:
                        T = "修改";
                        Model.Order_OrgWalt_T OrgWalt = base.GetListBy(u => u.FormMerID == info.FormMerID).First();
                        Help.FuZhi<Model.Order_OrgWalt_T>.FZ(ref OrgWalt, info);
                        ret = base.Modify(OrgWalt);
                        break;
                    case 3:
                        T = "删除";
                        OrgWalt = base.GetListBy(u => u.FormMerID == info.FormMerID).First();
                        OrgWalt.OrgWaltState = 0;
                        ret = base.Modify(OrgWalt);
                        break;
                }
                if (ret > 0)
                {

                    result.BS = "1";
                    result.Msg = "更新成功";
                }
                else
                {
                    result.BS = "0";
                    result.Msg = "更新失败";
                }
            }
            catch (Exception ex)
            {
                result.BS = "-99";
                result.Msg = "更新失败" + ex.Message;
            }
            #endregion
            return os.StringOfObject(result, RETID);
        }
    }
}
